package Marta;

import GenCol.entity;
import MartaModeling.MartaConst;


public class Train extends entity{

	private static final int CAPACITY = MartaConst.CAR_CAPACITY * MartaConst.CARS_IN_TRAIN;
	
	/**
	 * How many passengers on board
	 * */
	private int numOnBoard;
	
	/**
	 * If the train is full(reach the capacity limit)
	 * **/
	private boolean isTrainFull = false;
	
	/**
	 * If the train is empty(0 passengers on board) 
	 * **/
	private boolean isTrainEmpty = true;
	
	/**
	 * Name of the train, it will be displayed on the screen
	 * */
	private String trainName;
	
	
	
	
	public String getTrainName() {
		return trainName;
	}


	public void setTrainName(String trainName) {
		this.trainName = trainName;
	}


	public int getNumOnBoard() {
		return numOnBoard;
	}


	public void setNumOnBoard(int numOnBoard) {
		this.numOnBoard = numOnBoard;
	}


	public boolean isTrainFull() {
		return isTrainFull;
	}


	public void setTrainFull(boolean isTrainFull) {
		this.isTrainFull = isTrainFull;
	}


	public boolean isTrainEmpty() {
		return isTrainEmpty;
	}


	public void setTrainEmpty(boolean isTrainEmpty) {
		this.isTrainEmpty = isTrainEmpty;
	}
	
	
	public Train(String trainName) {
		super(trainName);
		this.trainName = trainName;
	}

	/**
	 * Passengers board on a train
	 * @param num number of passengers want to get on
	 * @return how many passengers failed to get on
	 * **/
	public int getOnTrain(int num) {
		int res = 0;
		
		int availableCapacity =  Train.CAPACITY - this.numOnBoard;
		
		if( availableCapacity <= num) { // more waiting ppl, no enuf space for every wating
			res = num - availableCapacity;
			this.numOnBoard = Train.CAPACITY;
			this.setTrainFull(true);
		} else { // enuf space for all the waiting ppl 
			this.numOnBoard += num; 
		}
		return res;
	}
	
	/**
	 * Passengers get off a train
	 * @param num number of passengers to get off a train
	 * @return # of passengers successfully get off
	 * **/
	public int getOffTrain(int num) {
		int res = 0;
		
		if(this.numOnBoard <= num) { // more ppl are supposed to get off
			res = this.numOnBoard;
			this.numOnBoard = 0;
			this.setTrainEmpty(true);
		} else {
			res = num;
			this.numOnBoard = this.numOnBoard - num;
		}
		
		return res;
	}
}
